package com.zkdcloud.aspectInterceptor.advice;

import com.xdja.interceptor.advice.HttpAdvice;
import com.xdja.interceptor.exception.InvokeException;
import com.xdja.interceptor.util.ValidateUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 分页数据校验
 *
 * @author zk
 * @since 2018/3/19
 */
@Component
public class PageAdvice implements HttpAdvice {
    public void doAdvice(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Map<String, Object> map) throws InvokeException {
        if(!"GET".equalsIgnoreCase(httpServletRequest.getMethod())){
            throw new InvokeException("not support other http method except get(无状态请求，应该使用GET请求)");
        }
        String pageNo = httpServletRequest.getParameter("pageNum");
        String pageSize = httpServletRequest.getParameter("pageSize");

        ValidateUtils.assertCondition(!StringUtils.isEmpty(pageNo),"页码不能为空");
        ValidateUtils.assertCondition(!StringUtils.isEmpty(pageSize),"页面大小不能为空");
    }
}
